package com.duanjw.algorithms.sort;

/**
 * 插入排序
 *
 * @author duanjw
 */
public class Insertion extends AbstractSort {
    @Override
    public void sort(Comparable[] array) {
        int length = array.length;
        for (int i = 0; i < length; i++) {
            for (int j = i; j > 0 && less(array[j], array[j - 1]); j--) {
                exch(array, j, j - 1);
            }
        }
    }

    public static void main(String[] args) {
        Insertion selection = new Insertion();
        Integer[] array = {1, 2, 4, 6, 5, 3};
        selection.sort(array);

        selection.show(array);
    }
}
